<script lang="ts">
  import { beforeUpdate } from 'svelte'
  import { page } from '@inertiajs/svelte'
  import type { Method } from '@inertiajs/core'
  import type { MulterFile } from '../types'

  export let headers: Record<string, string>
  export let method: Method
  export let form: Record<string, unknown>
  export let files: MulterFile[] | object = {}
  export let url: string
  export let query: Record<string, unknown>

  const dump = {
    headers,
    method,
    form,
    files,
    query,
    url,
    $page: $page,
  }

  beforeUpdate(() => {
    window._inertia_request_dump = dump
  })
</script>

<div>
  <div class="text">This is Inertia page component containing a data dump of the request</div>
  <hr />
  <pre class="dump" style="white-space: pre-wrap; word-break: keep-all;">{JSON.stringify(dump)}</pre>
</div>
